package com.poorstu.web;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import com.poorstu.manager.PartTimeManager;
import com.common.base.web.BaseAction;
import com.poorstu.model.PartTimeMod;

public class PartTimeAddAction extends BaseAction {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		try{
		DynaActionForm dyna=(DynaActionForm)form;
		String company=(String)dyna.get("company");
		int money=(Integer)dyna.get("salary");
		String contactName=(String)dyna.get("contactName");
		String conPhone=(String)dyna.get("contactPhone");
		String emile=(String)dyna.get("contactEmail");
		int peopleNum=(Integer)dyna.get("number");
		String content=(String)dyna.get("content");
		String status=(String)dyna.get("status");
		String startTime=(String)dyna.get("starTime");
		String  endTime=(String)dyna.get("endTime");
		String other=(String)dyna.get("other");
		
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Date startDate = format.parse(startTime);
		Date endDate=format.parse(endTime);
		
		PartTimeMod partTime=new  PartTimeMod();
		partTime.setCompany(company);
		partTime.setConPhone(conPhone);
		partTime.setContactName(contactName);
		partTime.setContent(content);
		partTime.setEmile(emile);
		partTime.setStartTime(startDate);
		partTime.setEndTime(endDate);
		partTime.setMoney(money);
		partTime.setPeopleNum(peopleNum);
		partTime.setStatus(status);
		partTime.setOther(other);
 
		
		PartTimeManager partTimeMag=(PartTimeManager)getBean("partTimeManager");
		
		boolean b=partTimeMag.addPartTime(partTime);
		if(b){
			return mapping.findForward("succ");
			
		}
	
		}catch(Exception e){
			e.printStackTrace();
			return  mapping.findForward("failure");
		}
		return  mapping.findForward("failure");
		}
	}
